<template>
  <div class="editor-workspace">
    <ruler :left="left" :top="top" />
    <playground />
  </div>
</template>

<script>
  import debounce from 'lodash/debounce'
  import mixin from '@/views/editor/mixin.js'
  import Ruler from './components/Ruler'
  import Playground from './components/Playground'
  export default {
    name: 'Workpace',
    components: {
      Ruler,
      Playground,
    },
    mixins: [mixin],
    data() {
      return {
        root: {},
        left: 0,
        top: 0,
      }
    },
    mounted() {
      const dom = this.root.$refs['editor-content']
      const scrollFunc = debounce((e) => {
        this.left = e.target.scrollLeft
        this.top = e.target.scrollTop
      }, 50)
      dom.addEventListener('scroll', scrollFunc)
      this.$once('hook:beforeDestroy', () => {
        dom.removeEventListener('scroll', scrollFunc)
      })
    },
  }
</script>

<style scoped>
  .editor-workspace {
    position: absolute;
    left: 0;
    top: 0;
    width: 2000px;
    height: 1500px;
    overflow: hidden;
  }
</style>
